package fr.umlv.m2.jee.pmlv.service.user.impl;

import javax.naming.NamingException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import fr.umlv.m2.jee.pmlv.service.user.User;

public class App {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext appContext = new ClassPathXmlApplicationContext(
				"ldap/springldap.xml");
		UserService ldapUser = (UserService) appContext
				.getBean("ldapUser");
		User user = ldapUser.getUserDetails("nogroup", "nogroup");
		if (user != null) {
			System.out.println(user.getCommonName());
			System.out.println(user.getLastname());
			System.out.println(user.getFirstname());
			System.out.println(user.getMail());
			System.out.println(user.getMobile());
			System.out.println(user.getNumber());
			System.out.println(user.getPostalAddress());
			System.out.println(user.getTelephone());
			System.out.println(user.getuId());
			try {
				String groupeDN = ldapUser.getUserGroups(user.getCommonName());
				if(groupeDN!=null) System.out.println(groupeDN);
				else System.out.println("no group for this user");
				
			} catch (NamingException e) {
				System.out.println("NamingException");
			}
		} else
			System.out.println("wrong username or password");

	}
}
